package com.github.tvbox.osc.ui.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.github.tvbox.osc.R;
import com.github.tvbox.osc.bean.Movie;
import com.github.tvbox.osc.picasso.RoundTransformation;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.MD5;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import me.jessyan.autosize.utils.AutoSizeUtils;

public class UserHotVodAdapter extends BaseQuickAdapter<Movie.Video, BaseViewHolder> {

    private int select_position = 0;

    public UserHotVodAdapter() {
        super(R.layout.item_user_hot_vod_new, new ArrayList<>());
    }

    public void setSelectPosition(int position) {
        if(this.select_position != position){
            this.select_position = position;
            notifyDataSetChanged();
        }
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, Movie.Video item) {
        helper.setText(R.id.title, item.name);
        ImageView ivHot = helper.getView(R.id.ivHot);
        //由于部分电视机使用glide报错
        if (!TextUtils.isEmpty(item.pic)) {
            Picasso.get()
                    .load(DefaultConfig.checkReplaceProxy(item.pic))
                    .transform(new RoundTransformation(MD5.string2MD5(item.pic + "position=" + helper.getLayoutPosition()))
                            .centerCorp(true)
                            .override(AutoSizeUtils.mm2px(mContext, 620), AutoSizeUtils.mm2px(mContext, 340))
                            .roundRadius(AutoSizeUtils.mm2px(mContext, 15), RoundTransformation.RoundType.ALL))
                    .placeholder(R.drawable.img_loading_placeholder)
                    .error(R.drawable.img_loading_placeholder)
                    .into(ivHot);
        } else {
            ivHot.setImageResource(R.drawable.img_loading_placeholder);
        }
    }
}
